package com.compass.mobile.ui.viewModel

import androidx.lifecycle.MutableLiveData
import com.compass.mobile.framework.utils.TipsToast
import com.compass.mobile.models.Appointment
import com.compass.mobile.models.OrderBean
import com.compass.mobile.network.callback.IApiErrorCallback
import com.compass.mobile.network.manager.ApiManager
import com.compass.mobile.network.viewmodel.BaseViewModel

/**
 * Description： 预约
 * Date:2024/6/25 11:12
 */
class AppointmentViewModel : BaseViewModel() {
    val cancelAppointmentLiveData = MutableLiveData<Any?>()
    val appointmentOrdersLiveData = MutableLiveData<MutableList<Appointment>?>()

    //获取问诊列表
    fun getAppointmentList(patientId: String?, type: String?, pageNo: Int, pageSize: Int = 10) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getAppointmentList(patientId, type, pageNo, pageSize)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty()) {
                appointmentOrdersLiveData.value = null
            } else {
                appointmentOrdersLiveData.value = it.list
            }
        })
    }


    //获取问诊列表
    fun cancelAppointment(pkSchappt: String?) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.cancelAppointment(pkSchappt)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            cancelAppointmentLiveData.value=it
        })
    }

}